// 线索管理  clue
import layer from '@/components/layer'
import dicts from '@/mixins/dicts'
import filters from '@/mixins/filters'
import permission from '@/components/permission'

export default {
	mixins: [dicts],
	data() {
		return {
			filter: filters.filters,
			search: {
				loading: false,
				list: [],
				timer: null
			},
			infoType: '',
			infoName: '',
			infoCode: '',
			tableData: {
				filter: {
					pageBean: {
						pageIndex: 1,
						pageSize: 10
					}
				},
				sizes: 10,
				data: [],
				rules: {
					reflectPhone: { pattern: /^1[3|5|6|7|8|9]\d{9}$/, message: '手机号格式不正确', trigger: 'blur' }
				}
			}
		}
	},
	components: {
		layer,
		permission
	},
	mounted() {
		this.sumbitSave();
	},
	methods: {
		// 筛选   
		sumbitSave() {
			if (this.riskCategoryForm.id) {
				let _category = this.dicts.riskCategory.find(item => item.id == this.riskCategoryForm.id)
				if (_category) {
					this.tableData.filter.riskCategory = _category.value
				}
			}
			else {
				this.tableData.filter.riskCategory = ''
			}
			if (this.riskTypeForm.value) {
				this.tableData.filter.riskType = this.riskTypeForm.value
			}
			else {
				this.tableData.filter.riskType = ''
			}
			if (this.riskLevelForm.value) {
				this.tableData.filter.riskLevel = this.riskLevelForm.value
			}
			else {
				this.tableData.filter.riskLevel = ''
			}
			api[this.ajaxType](this.tableData.filter).then(res => {
				this.tableData.total = res.totalCount
				this.tableData.data = res.list
				console.log(this.tableData.data)
			}, error => { })

		},
		// 重置筛选条件
		reset() {
			this.initRiskData()
			this.tableData.filter = { pageBean: { pageIndex: 0, pageSize: 10 } }
			this.sumbitSave()
		},
		// 分页改变
		sizeChange(val) {
			this.tableData.filter.pageBean.pageIndex = 1
			this.tableData.filter.pageBean.pageSize = val
			this.sumbitSave()
		},
		// 当前页面改变
		currentChange(val) {
			this.tableData.filter.pageBean.pageIndex = val
			this.sumbitSave()
		},
		setSalesDeptName(e) {
			let split = e.split('_')
			this.formData[this.infoType][this.infoCode] = split[0]
			this.formData[this.infoType][this.infoName] = split[1]
		},
		setSalesDeptType(info, code, name) {
			this.infoType = info
			this.infoName = name
			this.infoCode = code
		},
		// 搜索所属营业部
		searchBusinessMethod() {
			if (this.search.list.length < 1) {
				if (this.search.timer) {
					clearTimeout(this.search.timer)
				}

				this.search.loading = true;
				this.search.timer = setTimeout(() => {
					api.queryDepartment({
						name: ''
					}).then(res => {
						this.search.loading = false
						this.search.list = res.department
					}).catch(res => {
						console.log(res)
					})
				}, 200)
			}
		},
	}
};